package com.alianzamedica.controllers.lot;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.objectsearch.web.tools.Converter;

import com.alianzamedica.models.TagWizardModel;

/**
 * @author carlos
 * 
 */
public class LotWizardSave extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Integer medicId = Converter.string2Integer(request
				.getParameter("medicId"));
		String idLote = request.getParameter("idLote");
		Integer lot=Integer.parseInt(idLote);
		String codigoLote = request.getParameter("codigoLote");
		String[] tags = request.getParameterValues("tag");
		TagWizardModel tagWizardModel = new TagWizardModel();
		boolean success = tagWizardModel.saveTags(medicId, lot, codigoLote,
				tags);
		String mensaje = "Lotes Guardados y Asignados de Manera Correcta";
		if (!success) {
			mensaje = "Los Lotes No se han podido Guardar, Verifique si los datos son correctos.";
		}
		String linkRetorno = "/admin/index.do";

		request.setAttribute("linkRetorno", linkRetorno);
		request.setAttribute("mensaje", mensaje);

		return mapping.findForward("success");
	}

}
